<?php


namespace app\adminapi\dao\member;


use app\common\dao\BaseHotelDao;
use app\common\model\member\MemberBenefit;
use app\common\model\member\MemberLevel;

/**
 * @projectName src
 */
class MemberBenefitDao extends BaseHotelDao
{
    public static function add(array $params)
    {
        MemberBenefit::create([
            'level_id' => $params['level_id'],
            'benefit_name' => $params['benefit_name'],
            'use_caluse' => $params['use_caluse'] ?? '',
            'use_dept' => $params['use_dept'] ?? '',
        ]);
    }

    public static function edit(array $params): bool
    {
        try {
            MemberBenefit::update($params);
            return true;
        } catch (\Exception $e) {
            self::setError($e->getMessage());
            return false;
        }
    }

    public static function delete(array $params)
    {
        MemberBenefit::destroy($params['id']);
    }

    public static function detail(array $params): array
    {
        return MemberBenefit::findOrEmpty($params['id'])->toArray();
    }

    public static function getAllData()
    {
        return MemberBenefit::order('id', 'desc')->select()->toArray();
    }
}